package cn.jaye.fabric.controller;

import cn.jaye.fabric.application.PeerApplicationService;
import cn.jaye.fabric.application.command.peer.CreatePeerCommand;
import cn.jaye.fabric.application.command.peer.ListMPeerChannelCommand;
import cn.jaye.fabric.application.command.peer.ListPeerCommand;
import cn.jaye.fabric.common.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Jaye
 * @create 2018-05-02 11:48
 */
@RestController
@RequestMapping("peer")
public class PeerController {

    @Autowired
    private PeerApplicationService peerApplicationService;

    @PostMapping("/create")
    public String create(HttpServletRequest request, @RequestBody CreatePeerCommand createPeerCommand) {
        return ResultUtil.success(peerApplicationService.create(createPeerCommand));
    }

    @PostMapping("list")
    public String list(HttpServletRequest request, @RequestBody ListPeerCommand listPeerCommand) {
        return ResultUtil.success(peerApplicationService.list(listPeerCommand));
    }

    @PostMapping("list/channelName")
    public String listChannelName(@RequestBody ListMPeerChannelCommand listMPeerChannelCommand) {
        return ResultUtil.success(peerApplicationService.listPeer(listMPeerChannelCommand));
    }
}
